XML Reading / Writing

About XML

well for starters XML is kinda like HTML, but with a different function.
You use like in HTML tags, for repesenting objects. Like <HTML></HTML> is repesenting the HTML document. Tags can have attributes like <FONT> have the attribute COLOR. XML is like a database, it can store information, and the most powerfull function of XML is that it also can store objects.

Sample of a XML file:

<?xml version="1.0" encoding="utf-8"?>
<root>
<settings version=1>
<Autologin Enabled=true>
<Username>Someone</Username>
<Password>Some password</Password>
</Autologin>
</settings>
</root>

This is a simple config file I created for a application im making. Let me explain what information this is doing.

The first line repesents the XML version and encoding.
The secound line is the Root element, that is needed for a XML document.
I define a element named settings, to store all my settings in. Ist kinda like a Object there can store a set of information.
The 3. is even a new element to store some login information and has one atribute: Enabled, there has the value True.
The 4. and 5. Is Elements only repersenting a string value, the username and password
The rest of the lines closes the already opened objects.

The XML format is very usefull for config files, as I used it here.
Back in time then I was a very new programmer, I used a simple text document to store my settings, so setting will be

Setting1
Setting2
Setting3|Value

and so on. But I went into a problem: Objects. I whanted a list there repesented games installed on the computer, at that time I simply solved it by creating a new document with a line of the game names and "|" to seperate a game name, and its path. This can be a good way for simple applications, but then we are talking about large application with alot of objects, and lot of values, then it would be very slow. XML can solve this easy by only using one file.

<?xml version="1.0" encoding="utf-8"?>
<root>
<settings version=1>
<Autologin Enabled=true>
<Username>Someone</Username>
<Password>Some password</Password>
</Autologin>
</settings>
<games>
<game>
<name>Game name</name>
<version>Game version</version>
</game>
<game>
<name>Game name</name>
<version>Game version</version>
<path>Game version</path>
</game>
</games>

</root>

There are other ways to do it, but this is the way i whanted to show.

Exsample for using XML is .NET Applications

Well this far, I can simply write, and by my self read anything that is writed in the file over this chapter. BUT how can we get the application to read it, and write it.

A sample is included (XML.sln) it repesents a simple application there has a list of projects and there progress, and some other information to the projects. A simply database by the way, but with some advanced function like a user can choose to add own values like "version" and "description" and tasks

Take a look at it.